package com.walkline.weibo.dao;

import java.util.Vector;

import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;

import com.walkline.util.Function;
import com.walkline.weibo.WeiboException;
import com.walkline.weibo.WeiboSDK;
import com.walkline.weibo.inf.Tag;
import com.walkline.weibo.inf.TagsWrapper;

public class WeiboTagsWrapper extends WeiboObject implements TagsWrapper
{
	private int _count = 0;
	private Vector _tags = new Vector();

	public WeiboTagsWrapper(WeiboSDK weibo, JSONObject jsonObject) throws WeiboException
	{
		super(weibo, jsonObject);

		JSONObject tagsWrapper = jsonObject;

		if (tagsWrapper != null)
		{
			_count = tagsWrapper.optInt("totle_number");

			JSONArray tags = tagsWrapper.optJSONArray("tags");
			if (tags != null)
			{
				JSONObject userObject;
				Tag tag;

				for (int i=0; i<tags.length(); i++)
				{
					try {
						userObject = (JSONObject) tags.get(i);

						tag = new WeiboTag(weibo, userObject);
						if (tag != null) {_tags.addElement(tag);}
					} catch (JSONException e) {Function.errorDialog(e.toString());}
				}
			}
		}
	}

	public int getCount() {return _count;}

	public Vector getTags() {return _tags;}
}